package com.neusoft.tijian.service.impl;

import com.neuedu.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.tijian.mapper.UsersMapper;
import com.neusoft.tijian.po.Users;
import com.neusoft.tijian.service.UsersService;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class UsersServiceImpl implements UsersService{
	
	@Autowired
	private UsersMapper usersMapper;

	/**
	 * 用户登录
	 * @param users
	 * @return
	 */
	@Override
	public Users getUsersByUserIdByPass(Users users) {
		log.info("用户登录:{}",users);
		Users user = usersMapper.getUsersByUserIdByPass(users);
		if (user != null){
			//存储信息info
			Map<String, Object> info = new HashMap<>();
			info.put("id",user.getUserId());
			info.put("realName",user.getRealName());

			//调用工具类生成jwt令牌
			String jwt = JwtUtils.generateJwt(info);
			user.setJwt(jwt);
		}
		return user;
	}

	/**
	 * 查询用户，根据id
	 * @param userId
	 * @return
	 */
	@Override
	public Users getUsersById(String userId) {
		return usersMapper.getUsersById(userId);
	}

	/**
	 * 保存用户信息
	 * @param users
	 * @return
	 */
	@Override
	public int saveUsers(Users users) {
		return usersMapper.saveUsers(users);
	}
}
